using System;
using System.Collections.Generic;
using System.Text;

namespace Typing_GUI.CLASS
{
    public class CKetQuaLuyenTap
    {
        #region"thuoc tinh"
            private int diemdatduoc;
            private int manguoidung;
            private int matclt;
            private int thoigian;
            private int soloisai;
            private string tocdo;
        #endregion

        #region"properties"
            public int Diemdatduoc
            {
                get { return diemdatduoc; }
                set { diemdatduoc = value; }
            }
            

            public int Manguoidung
            {
                get { return manguoidung; }
                set { manguoidung = value; }
            }
            

            public int Matclt
            {
                get { return matclt; }
                set { matclt = value; }
            }
            

            public int Soloisai
            {
                get { return soloisai; }
                set { soloisai = value; }
            }
            
            public int Thoigian
            {
                get { return thoigian; }
                set { thoigian = value; }
            }
           

            public string Tocdo
            {
                get { return tocdo; }
                set { tocdo = value; }
            }
        #endregion

        #region"phuong thuc"

        public bool createResult()
        {
            string sql = "insert into KetQuaLuyenTap ";
            sql += "(MaToChucLuyenTap,MaNguoiDung,DiemDatDuoc,ThoiGian,SoLoiSai,TocDo)";
            sql += " values(" + this.matclt.ToString() + "," + this.manguoidung.ToString();
            sql += "," + this.diemdatduoc.ToString() + "," + this.thoigian.ToString();
            sql += "," + this.soloisai.ToString() + "," + this.tocdo + ")";
            if (!DataProvider.ExecuteNonQuery(sql))
                return false;
            return true;
        }

        public bool deleteResult()
        {
            string sql = "delete from KetQuaLuyenTap where MaToChucLuyenTap=" + this.matclt.ToString();
            sql += " and MaNguoiDung=" + this.manguoidung.ToString();
            if (!DataProvider.ExecuteNonQuery(sql))
                return false;
            return true;
        }

        public bool updateResult()
        {
            string sql = "update KetQuaLuyenTap set";
            sql += " DiemDatDuoc=" + this.diemdatduoc.ToString();
            sql += ",ThoiGian=" + this.thoigian.ToString();
            sql += ",SoLoiSai=" + this.soloisai.ToString();
            sql += ",TocDo=" + this.tocdo.ToString();
            sql += " where MaToChucLuyenTap=" + this.matclt.ToString();
            sql += " and MaNguoiDung=" + this.manguoidung.ToString();
            if (!DataProvider.ExecuteNonQuery(sql))
                return false;
            return true;
        }

        public static bool CheckExistResult(int examID, int userID)
        {
            string sql = "select * from KetQuaLuyenTap where MaToChucLuyenTap=" + examID.ToString() + " and MaNguoiDung=" + userID.ToString();
            System.Data.DataTable dt = DataProvider.ExecuteQuery(sql);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }

        public static CKetQuaLuyenTap GetExamResult(int examID, int userID)
        {
            CKetQuaLuyenTap result = new CKetQuaLuyenTap();
            string sql = "select*from KetQuaLuyenTap where MaToChucLuyenTap=" + examID.ToString() + " and MaNguoiDung=" + userID.ToString();
            System.Data.DataTable dt = DataProvider.ExecuteQuery(sql);
            if (dt.Rows.Count <= 0)
                return null;
            System.Data.DataRow dr = dt.Rows[0];
            result.matclt = int.Parse(dr["MaToChucLuyenTap"].ToString());
            result.manguoidung = int.Parse(dr["MaNguoiDung"].ToString());
            result.Diemdatduoc = int.Parse(dr["DiemDatDuoc"].ToString());
            result.thoigian = int.Parse(dr["ThoiGian"].ToString());
            result.tocdo = dr["TocDo"].ToString();
            result.soloisai = int.Parse(dr["SoLoiSai"].ToString());
            return result;
        }
        #endregion
        }
}
